import React, { createContext, useContext, ReactNode } from 'react';

interface NavigationContextType {
  navigateToSeries: (
    experimentId: number,
    categoryId: number,
    seriesId: number
  ) => void;
}

const NavigationContext = createContext<NavigationContextType | undefined>(undefined);

export const NavigationProvider: React.FC<{
  children: ReactNode;
  navigateToSeries: (
    experimentId: number,
    categoryId: number,
    seriesId: number
  ) => void;
}> = ({ children, navigateToSeries }) => {
  return (
    <NavigationContext.Provider value={{ navigateToSeries }}>
      {children}
    </NavigationContext.Provider>
  );
};

export const useNavigation = () => {
  const context = useContext(NavigationContext);
  if (context === undefined) {
    // 如果没有提供 Context，返回一个空函数避免报错
    return {
      navigateToSeries: () => {
        console.warn('NavigationContext not provided');
      },
    };
  }
  return context;
};

